using ASP;
using HoWave.Web;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class UserControls_shopOrder : UserControl
{
	protected GridView GridView1;
	protected HiddenField hd_NeedInvoice;
	protected HiddenField hd_deliverType;
	protected HiddenField hd_NeedInvoiceOrder;
	protected HiddenField hd_InvoiceTotalPrice;
	protected Label Label1;
	protected Label Label2;
	protected Label Label3;
	protected Label Label4;
	protected Label Label5;
	protected Label Label6;
	protected Label Label7;
	protected Label Label8;
	protected Label Label9;
	protected Label Label10;
	protected Label Label11;
	protected Label Label12;
	protected Label Label13;
	protected Label Label14;
	protected TextBox TextBox1;
	protected HtmlTableRow inverText;
	protected TextBox Remark;
	protected string _productIDS = string.Empty;
	protected string _productNums = string.Empty;
	protected string _productPrices = string.Empty;
	protected string _deliverTypeName = string.Empty;
	protected decimal _deliverTotalPrice = 0m;
	protected decimal _TotalMoneyGoods = 0m;
	protected decimal _TotalMoney = 0m;
	protected int _buyerID = 0;
	protected string _address = string.Empty;
	protected string _contactName = string.Empty;
	protected string _contactPhone = string.Empty;
	protected string _contactZipCode = string.Empty;
	protected string _contactEmail = string.Empty;
	protected int _deliverTypeID = 0;
	private UserBll _shop_Buyer = null;
	private Shop_Product _product = null;
	private UserInfoBll _buyerInfo = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	public string productIDS
	{
		get
		{
			return this._productIDS;
		}
		set
		{
			this._productIDS = value;
		}
	}
	public string productNums
	{
		get
		{
			return this._productNums;
		}
		set
		{
			this._productNums = value;
		}
	}
	public string productPrices
	{
		get
		{
			return this._productPrices;
		}
		set
		{
			this._productPrices = value;
		}
	}
	public string deliverTypeName
	{
		get
		{
			return this._deliverTypeName;
		}
		set
		{
			this._deliverTypeName = value;
		}
	}
	public decimal deliverTotalPrice
	{
		get
		{
			return this._deliverTotalPrice;
		}
		set
		{
			this._deliverTotalPrice = value;
		}
	}
	public decimal TotalMoneyGoods
	{
		get
		{
			return this._TotalMoneyGoods;
		}
		set
		{
			this._TotalMoneyGoods = value;
		}
	}
	public decimal TotalMoney
	{
		get
		{
			return this._TotalMoney;
		}
		set
		{
			this._TotalMoney = value;
		}
	}
	public int buyerID
	{
		get
		{
			return this._buyerID;
		}
		set
		{
			this._buyerID = value;
		}
	}
	public string address
	{
		get
		{
			return this._address;
		}
		set
		{
			this._address = value;
		}
	}
	public string contactName
	{
		get
		{
			return this._contactName;
		}
		set
		{
			this._contactName = value;
		}
	}
	public string contactPhone
	{
		get
		{
			return this._contactPhone;
		}
		set
		{
			this._contactPhone = value;
		}
	}
	public string contactZipCode
	{
		get
		{
			return this._contactZipCode;
		}
		set
		{
			this._contactZipCode = value;
		}
	}
	public string contactEmail
	{
		get
		{
			return this._contactEmail;
		}
		set
		{
			this._contactEmail = value;
		}
	}
	public int deliverType
	{
		get
		{
			return this._deliverTypeID;
		}
		set
		{
			this._deliverTypeID = value;
		}
	}
	protected UserBll shop_buyer
	{
		get
		{
			UserBll shop_Buyer;
			if (this._shop_Buyer == null)
			{
				this._shop_Buyer = new UserBll();
				shop_Buyer = this._shop_Buyer;
			}
			else
			{
				shop_Buyer = this._shop_Buyer;
			}
			return shop_Buyer;
		}
	}
	protected Shop_Product product
	{
		get
		{
			Shop_Product product;
			if (this._product == null)
			{
				this._product = new Shop_Product();
				product = this._product;
			}
			else
			{
				product = this._product;
			}
			return product;
		}
	}
	protected UserInfoBll buyerInfo
	{
		get
		{
			UserInfoBll buyerInfo;
			if (this._buyerInfo == null)
			{
				this._buyerInfo = new UserInfoBll();
				buyerInfo = this._buyerInfo;
			}
			else
			{
				buyerInfo = this._buyerInfo;
			}
			return buyerInfo;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.loadinfo();
			this.Label1.Text = this.deliverTypeName;
			this.Label2.Text = this.deliverTotalPrice.ToString();
			this.loadcontactInfo();
			this.loadcontactInfo1();
			this.inverText.Visible = false;
			this.hd_deliverType.Value = this.deliverType.ToString();
			this.RepartPrice();
			this.Label3.Text = Math.Round(decimal.Parse(this.TotalMoneyGoods.ToString()), 2).ToString();
			this.Label4.Text = Math.Round(decimal.Parse(this.TotalMoney.ToString()), 2).ToString();
		}
	}
	public void RepartPrice()
	{
		decimal num = 0m;
		Shop_Product shop_Product = new Shop_Product();
		for (int i = 0; i < this.GridView1.Rows.Count; i++)
		{
			int partID = int.Parse(((HiddenField)this.GridView1.Rows[i].FindControl("HiddenID")).Value);
			if (shop_Product.IfJustPart(partID))
			{
				DataTable partProduct = shop_Product.GetPartProduct(partID);
				if (partProduct != null)
				{
					decimal d = decimal.Parse(partProduct.Rows[0]["yikouPrice"].ToString());
					int value = int.Parse(this.GridView1.Rows[i].Cells[3].Text);
					this.GridView1.Rows[i].Cells[4].Text = (d * value).ToString();
				}
			}
		}
		for (int j = 0; j < this.GridView1.Rows.Count; j++)
		{
			num = Math.Round(num + decimal.Parse(this.GridView1.Rows[j].Cells[4].Text), 2);
		}
		decimal totalMoney = num + this.deliverTotalPrice;
		this.TotalMoneyGoods = num;
		this.TotalMoney = totalMoney;
	}
	private DataTable getProducts()
	{
		string productIDS = this.productIDS;
		return this.product.getProductadnshopByProductIDS(productIDS);
	}
	private DataTable setNewDataTable()
	{
		DataTable dataTable = new DataTable();
		DataColumn column = new DataColumn("productID", typeof(int));
		dataTable.Columns.Add(column);
		DataColumn column2 = new DataColumn("productName", typeof(string));
		dataTable.Columns.Add(column2);
		DataColumn column3 = new DataColumn("productNum", typeof(int));
		dataTable.Columns.Add(column3);
		DataColumn column4 = new DataColumn("shopName", typeof(string));
		dataTable.Columns.Add(column4);
		DataColumn column5 = new DataColumn("shopID", typeof(int));
		dataTable.Columns.Add(column5);
		DataColumn column6 = new DataColumn("total", typeof(decimal));
		dataTable.Columns.Add(column6);
		DataColumn column7 = new DataColumn("StandPrice", typeof(decimal));
		dataTable.Columns.Add(column7);
		DataColumn column8 = new DataColumn("NeedInvoice", typeof(bool));
		dataTable.Columns.Add(column8);
		DataColumn column9 = new DataColumn("TaxRate", typeof(decimal));
		dataTable.Columns.Add(column9);
		DataColumn column10 = new DataColumn("ShoppingCarGuige", typeof(string));
		dataTable.Columns.Add(column10);
		DataColumn column11 = new DataColumn("SizeAttribute", typeof(string));
		dataTable.Columns.Add(column11);
		string[] array = this.productIDS.Split(new char[]
		{
			','
		});
		string[] array2 = this.productNums.Split(new char[]
		{
			','
		});
		string[] array3 = this.productPrices.Split(new char[]
		{
			','
		});
		DataTable products = this.getProducts();
		foreach (DataRow dataRow in products.Rows)
		{
			DataRow dataRow2 = dataTable.NewRow();
			dataRow2["productName"] = dataRow["ProductName"].ToString();
			dataRow2["shopName"] = dataRow["shopName"].ToString();
			dataRow2["shopID"] = int.Parse(dataRow["shopID"].ToString());
			dataRow2["StandPrice"] = decimal.Parse(dataRow["StandPrice"].ToString());
			dataRow2["productID"] = int.Parse(dataRow["productID"].ToString());
			dataRow2["NeedInvoice"] = bool.Parse(dataRow["NeedInvoice"].ToString());
			dataRow2["TaxRate"] = decimal.Parse(dataRow["TaxRate"].ToString());
			dataRow2["ShoppingCarGuige"] = dataRow["ShoppingCarGuige"].ToString();
			dataRow2["SizeAttribute"] = dataRow["SizeAttribute"].ToString();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i] == dataRow["productID"].ToString())
				{
					dataRow2["productNum"] = int.Parse(array2[i]);
					dataRow2["total"] = int.Parse(array2[i]) * decimal.Parse(dataRow["StandPrice"].ToString());
					if (array3[i] != "")
					{
						dataRow2["StandPrice"] = decimal.Parse(array3[i]);
						dataRow2["total"] = int.Parse(array2[i]) * decimal.Parse(array3[i]);
					}
				}
			}
			dataTable.Rows.Add(dataRow2);
		}
		return dataTable;
	}
	private void loadinfo()
	{
		DataSet dataSet = new DataSet();
		dataSet.Tables.Add(this.setNewDataTable());
		this.GridView1.DataSource = dataSet;
		this.GridView1.DataBind();
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			CheckBox checkBox = (CheckBox)gridViewRow.FindControl("cb_select");
			CheckBox checkBox2 = (CheckBox)gridViewRow.FindControl("isNeedInvoice");
			if (checkBox2.Checked)
			{
				checkBox.Enabled = true;
			}
			else
			{
				checkBox.Enabled = false;
			}
		}
	}
	private void loadcontactInfo()
	{
		DataTable userByUserID = this.shop_buyer.GetUserByUserID(this.buyerID);
		DataTable userInfoByUserID = this.buyerInfo.GetUserInfoByUserID(this.buyerID);
		this.Label5.Text = userInfoByUserID.Rows[0]["TrueName"].ToString();
		this.Label6.Text = userInfoByUserID.Rows[0]["MobilePhone"].ToString();
		this.Label7.Text = userInfoByUserID.Rows[0]["Address"].ToString();
		this.Label8.Text = userInfoByUserID.Rows[0]["ZipCode"].ToString();
		this.Label9.Text = userByUserID.Rows[0]["Email"].ToString();
	}
	private void loadcontactInfo1()
	{
		this.Label10.Text = this.contactName;
		this.Label11.Text = this.contactPhone;
		this.Label12.Text = this.address;
		this.Label13.Text = this.contactZipCode;
		this.Label14.Text = this.contactEmail;
	}
	protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
	{
		decimal num = 0m;
		bool flag = false;
		string text = "";
		foreach (GridViewRow gridViewRow in this.GridView1.Rows)
		{
			CheckBox checkBox = (CheckBox)gridViewRow.FindControl("cb_select");
			CheckBox checkBox2 = (CheckBox)gridViewRow.FindControl("isNeedInvoice");
			if (checkBox.Checked)
			{
				text += "1,";
				flag = true;
				if (checkBox2.Checked)
				{
					HiddenField hiddenField = (HiddenField)gridViewRow.FindControl("hd_NeedInvoice");
					num += decimal.Parse(gridViewRow.Cells[4].Text) * (decimal.Parse(hiddenField.Value) / 100m);
				}
			}
			else
			{
				text += "0,";
			}
		}
		this.hd_InvoiceTotalPrice.Value = num.ToString();
		decimal num2 = decimal.Parse(this.Label3.Text) + num + decimal.Parse(this.Label2.Text);
		this.Label4.Text = num2.ToString();
		if (flag)
		{
			this.inverText.Visible = true;
			this.hd_NeedInvoiceOrder.Value = "1";
		}
		else
		{
			this.inverText.Visible = false;
			this.TextBox1.Text = "";
			this.hd_NeedInvoiceOrder.Value = "0";
		}
		this.hd_NeedInvoice.Value = text;
	}
}
